package com.cheer.controller;

import com.cheer.common.Result;
import com.cheer.dto.MallCouponLoginDTO;
import com.cheer.dto.MallCouponUpdateDTO;
import com.cheer.service.AuthService;
import com.cheer.service.MallCouponService;
import com.cheer.service.MallOrderService;
import com.cheer.service.MallSalesroomService;
import com.cheer.vo.MallCouponVO;
import com.cheer.vo.SimpleObjectVO;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import javax.validation.Valid;
import java.util.List;

/**
 * @author cheer
 */
@RestController
@RequestMapping("/coupon")
public class MallCouponController {

    @Autowired
    private MallCouponService mallCouponService;
    @Autowired
    private AuthService authService;

    @ApiOperation("查询电子券码可选择的门店")
    @GetMapping("/salesroom/list")
    public Result<List<SimpleObjectVO>> listSalesroom(@RequestParam String number,
                                                      HttpSession session) {
        authService.getUserId(session);
        return Result.success(mallCouponService.listSalesroom(number));
    }

    @ApiOperation("门店登录")
    @PostMapping("/login")
    public Result<MallCouponVO> login(@RequestBody @Valid MallCouponLoginDTO couponLoginDTO,
                                      HttpSession session) {
        authService.getUserId(session);
        return Result.success(mallCouponService.login(couponLoginDTO));
    }

    @ApiOperation("优惠码核销")
    @PostMapping("/update")
    public Result update(@RequestBody @Valid MallCouponUpdateDTO couponUpdateDTO,
                         HttpSession session) {
        authService.getUserId(session);
        mallCouponService.update(couponUpdateDTO);
        return Result.success();
    }

}
